#ifndef DOCUMENT_H
#define DOCUMENT_H

#include <QHash>
#include <QList>
#include <QString>
#include <QStringList>

class Document
{
public:
    friend class DocumentCollection;

    Document();
    Document(const QString &file);
    QStringList terms() const {return content.keys();}
    bool contains(const QString &term) const {return content.contains(term);}
    int tf(const QString &term) const {return content[term];}
    double similarityCos(const Document &doc) const;
    double similarityEuclid(const Document &doc) const;
    double similarityManhattan(const Document &doc) const;
    double similarityHamming(const Document &doc) const;
    double similarityDice(const Document &doc) const;
    double similarityJaccard(const Document &doc) const;

    friend QDataStream &operator<<(QDataStream &out, const Document &doc);
    friend QDataStream &operator>>(QDataStream &in, Document &doc);

private:
    inline double dot(const Document &doc) const;
    inline double norm() const;

    QString name;
    QHash<QString, int> content;        // <term, number of occurences>
    QHash<QString, float> weights;      // <term, weight>
};

QDataStream &operator<<(QDataStream &out, const Document &doc);
QDataStream &operator>>(QDataStream &in, Document &doc);

#endif // DOCUMENT_H
